import type { Dictionary, Join, PaginationQuery, SortCriteria } from './types'

interface BaseTableParams {
  table: string
}

export interface CreateTableParams extends BaseTableParams {
  cols: Dictionary
}

export interface FixedTableParams extends CreateTableParams {
  renames?: Dictionary
}

export type DropTableParams = BaseTableParams
export type TableExistsParams = BaseTableParams
export type TruncateTableParams = BaseTableParams

export interface RenameTableParams {
  from: string
  to: string
}

export type GetTableColumnsParams = BaseTableParams
export type GetTableUsedParams = BaseTableParams

export interface SetTableUsedParams extends BaseTableParams {
  id: string
}

interface ColumnParams extends BaseTableParams {
  name: string
}

export interface AddColumnParams extends ColumnParams {
  type: string
}

export interface RenameColumnParams extends BaseTableParams {
  from: string
  to: string
}

export type ColumnExistsParams = ColumnParams
export type DropColumnParams = ColumnParams

interface RecordParams extends BaseTableParams {
  data: any
}

export interface InsertRecordParams extends RecordParams {}

export interface UpdateRecordParams extends RecordParams {
  where: any
}

export interface DeleteRecordParams extends BaseTableParams {
  where: any
}

export interface SaveEntityParams extends RecordParams {}

export interface UpdateEntityParams extends RecordParams {}

export interface DeleteEntityParams extends BaseTableParams {
  id: string
}

export interface PaginateEntityParams extends BaseTableParams {
  pager: PaginationQuery
}

export interface AggregateParams extends BaseTableParams {
  column?: string
  conditions?: Dictionary
  groupBy?: string
}

export interface SelectRecordsParams extends BaseTableParams {
  conditions: Dictionary
  limit?: number
  offset?: number
  orderBy?: SortCriteria[]
}

export interface SelectOneRecordParams extends BaseTableParams {
  conditions: Dictionary
}

export interface SelectJoinRecordParams extends SelectRecordsParams {
  joins: Join[]
}

export interface ExecuteRawSqlParams {
  sql: string
  params?: any[]
}
